//
//  HYOUSearchDetailCollectionView.m
//  BestGift
//
//  Created by 温晓宇 on 16/1/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HYOUSearchDetailCollectionView.h"
#import "HYOUSearchDetailCollectionViewCell.h"
@implementation HYOUSearchDetailCollectionView
//-(void)dealloc{
//    [_myCollectionView release];
//    [_bigArray release];
//    [_delegate release];
//    [super dealloc];
//}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 设置item大小的
    flowLayout.itemSize = CGSizeMake((WIDTH - 30) / 2, (WIDTH - 30) / 2 + 50);
    // 设置item与屏幕四周的间距
    // 边界距离:上, 左, 下, 右
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
//    [flowLayout release];
    //    [flowLayout release];
    //    // 设置最小行间距
    //    flowLayout.minimumLineSpacing = 10;
    //    // 设置最小列间距
    //    flowLayout.minimumInteritemSpacing = 1;
    self.myCollectionView = [[HYOUBaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64) collectionViewLayout:flowLayout];
    
    [self.myCollectionView registerClass:[HYOUSearchDetailCollectionViewCell class] forCellWithReuseIdentifier:@"collection"];
    
//    self.myCollectionView.backgroundColor = RGBA(242, 242, 242, 1);
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    [self.myCollectionView reloadData];
    [self addSubview:self.myCollectionView];
    [_myCollectionView release];

}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.bigArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.bigArray != 0) {
    HYOUSearchDetailCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];
    cell.model = [self.bigArray objectAtIndex:indexPath.row];
        return cell;
    }else{
        HYOUSearchDetailCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];
//        cell.model = [self.bigArray objectAtIndex:indexPath.row];
        return cell;
    }
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    HYOUHotModel *model = [self.bigArray objectAtIndex:indexPath.row];
    NSLog(@"%@",model.id);
    NSString *url = [NSString stringWithFormat:@"http://www.liwushuo.com/items/%@",model.id];
#pragma mark -- 审核 协议传值
    [self.delegate searchDetail:url];
    
}
-(void)setBigArray:(NSMutableArray *)bigArray{
    if (_bigArray != bigArray) {
        [_bigArray release];
        _bigArray = [bigArray retain];
    }
    [self.myCollectionView reloadData];
}


@end
